home *** CD-ROM | disk | FTP | other *** search
- package sub_arctic.lib;
-
- import sub_arctic.input.display_help;
- import sub_arctic.input.event;
- import sub_arctic.constraints.std_function;
- import java.awt.Point;
-
- /**
- * This is a general purpose container which can take any object
- * as its only child. Once an object is put in this container, the
- * container can generate a "display help" string onto the
- * top of the containing interface. This display help string is
- * generated after the pointer has been stationary on this object
- * for a few seconds (i.e. when we get told mouse_stationary())
- *
- * @author Ian Smith
- */
- public class display_help_container
- extends base_parent_interactor implements display_help {
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * The help text
- */
- protected String _text;
-
- /**
- * Retrieve the current help text.
- * @return String the current help text string
- */
- public String text() { return _text;}
-
- /**
- * Set the current help text.
- * @param String t the new text
- */
- public void set_text(String t) { _text=t;}
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Construct a display help container given an interactor and
- * a string.
- * @param interactor i the interactor to display the help for
- * @param String text the help text to display (should be short)
- */
- public display_help_container(interactor i, String text) {
- super(0,0,10,10); /* temporary */
- _text=text;
- set_w_constraint(std_function.offset(FIRST_CHILD.W(),0));
- set_h_constraint(std_function.offset(FIRST_CHILD.H(), 0));
- setup_for_fixed_children(1);
- set_child(0,i);
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This method is called when the pointer enters our area and
- * when no other agent has dispatched the event. We do nothing here
- * since we are planning to display help text.
- *
- * @param event evt the event to dispatch.
- * @param Object user_info the object you passed to the pick_collector at
- * pick_time.
- * @return boolean return true if you dispatched this event.
- */
- public boolean mouse_enter(event evt, Object user_info) {
- return true;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This method is called when the pointer leaves our area. This method
- * does nothing, we are only using the display help interface.
- *
- * @param event evt the event to dispatch
- */
- public void mouse_exit(event evt) {
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This is where we stash the top level's extra child while its
- * up.
- */
- protected label help_text;
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This method is called to inform the object that the help text
- * should be displayed now.
- */
- public void help_open() {
- top_level top=get_top_level();
- Point global;
- int x;
-
- /* there is no top level, give up */
- if (top==null) {
- return;
- }
-
- /* normal case: convert our 0,0 to the top_levels coord system */
- global=local_to_global(0,0);
-
- /*make the label we want */
- help_text=new label(text());
- help_text.set_boxed(true);
- help_text.set_opaque(true);
-
- /* set the x coordinate... */
- x=global.x;
- /* is the string just too big?*/
- if (help_text.w()>top.w()) {
- /* it is, so just do what you can... */
- x=0;
- } else {
- /* it fits, do we need to right justify?*/
- if (x+help_text.w()>top.w()) {
- x=top.w()-help_text.w();
- }
- }
-
- /* set the coords */
- help_text.set_x(x);
- help_text.set_y(global.y+h());
- top.add_child(help_text);
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This method is called to inform the object that the help text
- * should not be displayed any longer.
- *
- * @param event evt the event the "caused" this input.
- */
- public void help_close(event evt) {
- top_level top=get_top_level();
- if (top!=null) {
- top.remove_child(help_text);
- }
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
- }
-
- /*=========================== COPYRIGHT NOTICE ===========================
-
- This file is part of the subArctic user interface toolkit.
-
- Copyright (c) 1996 Scott Hudson and Ian Smith
- All rights reserved.
-
- The subArctic system is freely available for most uses under the terms
- and conditions described in
- http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html
- and appearing in full in the lib/interactor.java source file.
-
- The current release and additional information about this software can be
- found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
-
- ========================================================================*/
-